var user_no ='133607';
$(document).ready(function () {
    var jsonData = getJsonData(user_no);
    // console.log(jsonData);
    let mostList = document.getElementById('mostList');
    let summary = document.getElementById('summary');
    let Things = [];
    let annualFunParents = [];
    let userRank = '';
    var annualFunCharSfc = [];
    var getEchart = [];
    // 调查问卷的
    // http://mes.abu.com:9000//AnnualSummary/AnnualSummary.asmx/InsertAnnualContent?user_no=string&content=string&opinion=string
    var url = "demo.json"/*json文件url，本地的就写本地的位置，如果是服务器的就写服务器的路径*/
    var res = JSON.parse(jsonData);
    // console.log(res);
    FunNameSfcFirst = res.FunNameSfcFirst;
    FunNameSfcLast = res.FunNameSfcLast;
    annualFunCharSfc = res.annualFunCharSfc;
    ClickCountBe = annualFunCharSfc.ClickCountBe;
    ClickCountMor = annualFunCharSfc.ClickCountMor;
    ClickCountNoon = annualFunCharSfc.ClickCountNoon;
    ClickCountAfter = annualFunCharSfc.ClickCountAfter;
    ClickCountEvening = annualFunCharSfc.ClickCountEvening;
    ClickCountNight = annualFunCharSfc.ClickCountNight;
    getEchart.push(ClickCountBe,ClickCountMor,ClickCountNoon,ClickCountAfter,ClickCountEvening,ClickCountNight);
    loginDate = res.LoginDateSfc;
    LoginName = res.LoginNameSfc;
    LoginTimeFirst = res.LoginTimeSfcFirst;
    LoginTimeFirst1 = LoginTimeFirst.split(' ');
    LoginTimeFirst2 = LoginTimeFirst1[0].split('-');
    LoginTimeLast = res.LoginTimeSfcLast;
    LoginTimeLast1 = LoginTimeLast.split(' ');
    LoginTimeLast2 = LoginTimeLast1[0].split('-')
    lastDay = res.LastDaySfc;
    lastDay1 = lastDay.split(' ');
    lastDay2 = lastDay1[0].split('-');
    totalDay = res.DaySfc;
    totalClick = res.TotalClickSfc;
    totalDay1 = loginDate.split(' ');
    totalDay2 = totalDay1[0].split('-');
    userRank = res.UserPositionSfc;
    userProportion = res.UserProportionSfc;
    annualFunParents = res.annualFunParentSfcs;
    userName = res.UserName;
    timeMost = res.LoginTimeFavSfc;
    Things = res.annualFunSfcs;
    TotalHour = parseInt(res.TotalDaySfc)*24;
    $('.earlyName').text(FunNameSfcFirst.split('.')[0]);
    $('.lastName').text(FunNameSfcLast.split('.')[0]);
    $('.totalHour').text(TotalHour);
    $('.LoginName').text(LoginName.split('.')[0]);
    $('.firstDay').text(totalDay2[0] + '.' + totalDay2[1] + '.' + totalDay2[2] + ' ' + totalDay1[1]);
    $('.lastDay').text(lastDay2[0] + '.' + lastDay2[1] + '.' + lastDay2[2]);
    $('.lastDay2').text( lastDay1[1]);
    $('.totalDay').text(totalDay);
    $('.user').text(userName);
    $('#user2').text(userName);
    $('.timeMost').text(timeMost);
    $('.totalClick').text(totalClick);
    $('.userProportion').text(userProportion);
    $('.userRank').text("Top" + userRank);
    $('.early').text(LoginTimeFirst2[0]+'.'+LoginTimeFirst2[1]+'.'+LoginTimeFirst2[2]);
    $('.early2').text(LoginTimeFirst1[1]);
    $('.last').text(LoginTimeLast2[0]+'.'+LoginTimeLast2[1]+'.'+LoginTimeLast2[2]);
    $('.last2').text(LoginTimeLast1[1]);
    getSummary();
    getMostBrowse();
    //$.ajax({
    //    type: 'GET',
    //    url: 'http://localhost:8080/AnnualSummary/AnnualSummaryReportSfc/src/json/' + user_no + '.json',
    //    dataType: 'json',
    //    async: true,
    //    cache: false,
    //    success: function (res) {
    //        loginDate = res.LoginDateSfc;
    //        LoginTimeFirst = res.LoginTimeSfcFirst;
    //        LoginTimeFirst1 = LoginTimeFirst.split(' ');
    //        LoginTimeFirst2 = LoginTimeFirst1[0].split('-');
    //        LoginTimeLast = res.LoginTimeSfcLast;
    //        LoginTimeLast1 = LoginTimeLast.split(' ');
    //        LoginTimeLast2 = LoginTimeLast1[0].split('-')
    //        lastDay = res.LastDaySfc;
    //        lastDay1 = lastDay.split(' ');
    //        lastDay2 = lastDay1[0].split('-');
    //        totalDay = res.DaySfc;
    //        totalClick = res.TotalClickSfc;
    //        totalDay1 = loginDate.split(' ');
    //        totalDay2 = totalDay1[0].split('-');
    //        userRank = res.UserPositionSfc;
    //        userProportion = res.UserProportionSfc;
    //        annualFunParents = res.annualFunParentSfcs;
    //        userName = res.UserName;
    //        timeMost = res.LoginTimeFavSfc;
    //        Things = res.annualFunSfcs;
    //        $('#firstDay').text(totalDay2[0]+'年'+totalDay2[1]+'月'+totalDay2[2]+'日'+' '+totalDay1[1]);
    //        $('#lastDay').text(lastDay2[0]+'年'+lastDay2[1]+'月'+lastDay2[2]+'日'+' '+lastDay1[1]);
    //        $('#totalDay').text(totalDay);
    //        $('#user').text(userName);
    //        $('#user2').text(userName);
    //        $('#timeMost').text(timeMost);
    //        getSummary();
    //        getMostBrowse();
    //        console.log("获取成功", res)
    //        //var fso = new ActiveXObject("Scripting.FileSystemObject"); 
    //        //var f = fso.createtextfile("AnnualSummaryReportSfc/aa.txt", 2, true);
    //        $('#mm').val("OK");
    //    }, 
    //    error: function (res){
    //        console.log("获取失败",res)
    //    }
    function getMostBrowse() {
        let thingsName = [];
        let thingsClick = [];
        let mostBrowse = 0;
        let str = '';
        if (Things.length < 8 && Things.length > 0) {
            for (let i = 0; i < Things.length; i++) {
                thingsName1 = Things[i].FunName;
                thingsName = thingsName1.split('.')[0]
                thingsClick = Things[i].ClickCount;
                str += `<li class="list-item">
                    <div class="lyric">执行<span style="display:inline-block;margin-right:10px">${thingsName}</span><span class="fc-red">${thingsClick}</span>次</div>
                </li>`
                mostBrowse += parseInt(thingsClick);
            }
        } else {
            for (let i = 0; i < 8; i++) {
                thingsName1 = Things[i].FunName;
                thingsName = thingsName1.split('.')[0]
                thingsClick = Things[i].ClickCount;
                str += `<li class="list-item">
                    <div class="lyric">执行<span style="display:inline-block;margin-right:10px">${thingsName}</span><span class="fc-red">${thingsClick}</span>次</div>
                </li>`
                mostBrowse += parseInt(thingsClick);
            }
        }
        $('#mostTitle').text("2020，你在SFC系统使用最多的是");
        $('#mostBrowse').html("我的最爱（<span class='number fc-red'>" + mostBrowse + "</span>次）");
        mostList.innerHTML = str;
    }
    function getSummary() {
        let annualName = [];
        let annualClick = [];
        let allClick = [];
        let str = '';
        let totalOperate = 0;
        for (let j = 0; j < annualFunParents.length; j++) {
           allClick = annualFunParents[j].ClickCount;
           totalOperate+=parseInt(allClick);
           $('.totalOperate').text(totalOperate)
        }
        if (annualFunParents.length < 10 && annualFunParents.length > 0) {
            for (let j = 0; j < annualFunParents.length; j++) {
                annualName1 = annualFunParents[j].FunName;
                annualFN1 = annualFunParents[0].FunName;
                annualFN = annualFN1.split('.')[0];
                annualName = annualName1.split('.')[0];
                annualClick = annualFunParents[j].ClickCount;
                $('.myFava').text(annualFN);
                $('.myFavaClick').text(annualFunParents[0].ClickCount);
                str += `<li class="item clearfix">
                <div class="left">
                  <span class="num s-fcRed">${j + 1}</span>
                  <div class="f-oh">
                    <div class="tt"><span class="in">&nbsp;${annualName}&nbsp;</span></div>
                  </div>
                </div>
                <div class="right">${annualClick}</div>
              </li>`
            }
            summary.innerHTML = `<p class="sumt">SFC系统</p>` + str;
        } else if (annualFunParents.length === 0) {
            str += '';
            summary.innerHTML = '';
        } else {
            for (let j = 0; j < 10; j++) {
                annualName1 = annualFunParents[j].FunName;
                annualFN1 = annualFunParents[0].FunName;
                annualFN = annualFN1.split('.')[0];
                annualName = annualName1.split('.')[0];
                annualClick = annualFunParents[j].ClickCount;
                $('.myFava').text(annualFN);
                $('.myFavaClick').text(annualFunParents[0].ClickCount);
                str += `<li class="item clearfix">
                <div class="left">
                  <span class="num s-fcRed">${j + 1}</span>
                  <div class="f-oh">
                    <div class="tt"><span class="in">&nbsp;${annualName}&nbsp;</span></div>
                  </div>
                </div>
                <div class="right">${annualClick}</div>
              </li>`
            }
            summary.innerHTML = `<p class="sumt"></p>` + str;
        }
    }

    // echarts
   // 基于准备好的dom，初始化echarts图表
   var myChart = echarts.init(document.getElementById('main'));
   var option = {
       color: ['rgb(243,134,126)'],
       tooltip : {
           show : true
       },
       legend : {
           data : [ '' ]
       },
       xAxis : [ {
           type : 'category',
           data : [ "清晨", "上午", "中午", "下午", "傍晚", "凌晨" ],
           splitLine:{
            show:false
          },
          axisLabel: {
            formatter: '{value}',
            rotate: "70",
            fontSize: 12,
            textStyle: {
                color: '#000'
            }
        }
       } ],
       yAxis : [ {
           type : 'value',
           splitLine:{
            show:false
          }
       } ],
       series : [ {
           "name" : "执行次数",
           "type" : "bar",
           "data" : getEchart,
           itemStyle: {
            normal: {
              label: {
                show: true, //开启显示
                position: 'top', //在上方显示
                textStyle: { //数值样式
                  color: 'black',
                  fontSize: 16
                }
              }
            }
          }
       } ],
       grid: {
         show:'true',
         borderWidth:'0'
        },
        label: {
          show: true,
          position: 'top',
          fontSize: 10
      }
   };

   // 为echarts对象加载数据 
   myChart.setOption(option);

})
 function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) { return pair[1]; }
        }
 }


function urlHtml(params) {
  //获取url地址
  var ts_href = window.location.href;
  var ts_mainText="";
  if(params==1){
    //获取地址最后一个“/”的下标
    var ts_indexof = ts_href.lastIndexOf("/");
    //获取地址“/”之后的的内容
    var ts_indexText = ts_href.substring(ts_indexof + 1);
    //获取地址“.html”的下标
    var ts_htmlBeforeText = ts_indexText.indexOf(".html");
    //获取 “/”到".html"之间的内容
    ts_mainText = ts_indexText.substring(0, ts_htmlBeforeText);
  }else if(params==2){
    //获取地址“/”的下标
    var ts_indexof = ts_href.lastIndexOf("/");
    //获取地址“/”之后的的内容
    var ts_indexText = ts_href.substring(ts_indexof + 1);
    ts_mainText = ts_indexText;
  }else if(params==3){
    //获取地址中倒数二个“/”下标的位置的之后的内容
    var urlParents=ts_href.substr(ts_href.lastIndexOf('/', ts_href.lastIndexOf('/') - 1) + 1);
    ts_mainText=urlParents
  }else if(params==4){
    //获取地址中倒数二个“/”的下标之后的内容
    var urlParents=ts_href.substr(ts_href.lastIndexOf('/', ts_href.lastIndexOf('/') - 1) + 1);
    //取到倒数二个“/”的下标的位置和.html之间的内容
    var beforeHtml = urlParents.indexOf(".html");
    if(beforeHtml==-1){
      ts_mainText=urlParents;
      
    }else{
      ts_mainText=urlParents.substring(0, beforeHtml);
    }
  }else{
    var urlParents=ts_href.substr(ts_href.lastIndexOf('/', ts_href.lastIndexOf('/') - 1) + 1);
    var beforeHtml = urlParents.indexOf(".html");
    if(beforeHtml==-1){
      ts_mainText=urlParents;
      
    }else{
      ts_mainText=urlParents.substring(0, beforeHtml);
    }
  }
  return ts_mainText;
}
// 新年flag
window.onload = function () {
  $('.otherPage').css('display','none');
 var change = document.querySelector(".changeText a"),
     bottom = document.querySelector(".bottom"),
     div = document.querySelectorAll(".bottom div"),
     li = document.querySelectorAll(".bottom ul li"),
     newSbmit = document.querySelector(".newSbmit")
     index = 0;
 change.onclick = function () {
      for(var i=0,len=div.length;i<len;i++){
          div[i].className="";
      }
       index++;
       //index等于div数组的长度
       if(index==len) index=0;
       div[index].className="active";
 }
 $('.bottom li').click(function() {
     // 获取.bottom li 的索引值
     $(this).toggleClass("liActive");
     // if($('.liActive').length<3) {
     //     $(this).toggleClass("liActive");
     // }else{
     //     alert('不能超过3个FLAG哦！');
     //     if($('.liActive').length==3){
     //         $(this).removeClass("liActive");
     //     }
     // }
 })
 var content = [];
//  http://localhost:8080/AnnualSummary/AnnualSummary.asmx/InsertFlagContent?user_no=string&content=string
 newSbmit.onclick = function () {
     for(var j=0;j<li.length; j++) {
         if(li[j].classList.contains('liActive')==true) {
             var licontent=li[j].innerText;
             $('.getText').append('<p>'+licontent+'</p>');
             content.push(licontent);
             $('.head').css('display','none');
             $('.otherPage').css('display','block');
         }
     }
     console.log('user_no',user_no)
     console.log('content',content);
 }
}